package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.system.api.RemoteUserService;
import com.sikaryofficial.system.api.domain.SysUser;
import com.sikaryofficial.system.api.domain.UserReq;
import com.sikaryofficial.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 用户服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService() {
            /**
             * 通过用户名查询用户信息
             *
             * @return 结果
             */
            @Override
            public R<SysUser> getInfoByh5() {
                return R.fail("getInfoByh5 info fail:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUserInfo(String username, String source) {
                return R.fail("get user info fail:" + throwable.getMessage());
            }

            /**
             * 通过用户名查询用户信息
             *
             * @param userId 用户名
             * @return 结果
             */
            @Override
            public R<SysUser> getUserByUserId(Long userId) {
                return R.fail("get user info fail:" + throwable.getMessage());
            }

            /**
             * 通过邮箱地址查询用户账户
             *
             * @param email 邮箱地址
             * @return 结果
             */
            @Override
            public R<String> getUserNameByEmail(String email) {
                return R.fail("getUserNameByEmail fail:" + throwable.getMessage());
            }

            /**
             * 获取账户名
             *
             * @param uuid
             * @return
             */
            @Override
            public R<String> getUserNameByUuid(String uuid) {
                return R.fail("getUserNameByUuid fail:" + throwable.getMessage());
            }

            /**
             * 邮箱唯一性校验
             *
             * @param email
             * @return
             */
            @Override
            public R<Boolean> checkEmailUnique(String email) {
                return R.fail("checkEmailUnique fail:" + throwable.getMessage());
            }

            /**
             * 删除用户账户
             *
             * @param userIds 用户ID集合
             * @return 结果
             */
            @Override
            public R<Integer> deleteUserByOwner(Long[] userIds) {
                return R.fail("deleteUserByOwner fail:" + throwable.getMessage());
            }

            /**
             * 删除会员账户
             *
             * @param userIds
             * @return
             */
            @Override
            public R<Integer> deleteMemberUsers(Long[] userIds) {
                return R.fail("deleteMemberUsers fail:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source) {
                return R.fail("register fail:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserByH5(UserReq req, String source) {
                return R.fail("registerUserByH5 fail:" + throwable.getMessage());
            }

            @Override
            public R<Long> registerForChannel(SysUser sysUser, String source) {
                return R.fail("registerForChannel fail:" + throwable.getMessage());
            }

            /**
             * 初始化H5用户角色和岗位
             *
             * @param user 用户ID集合
             * @return 结果
             */
            @Override
            public R<Integer> initH5UserRoleAndPost(SysUser user) {
                return R.fail("initH5UserRoleAndPost fail:" + throwable.getMessage());
            }

            /**
             * 初始化H5用户角色和岗位
             *
             * @param userId 用户ID
             * @return 结果
             */
            @Override
            public R<SysUser> getSysUserInfoCacheById(Long userId) {
                return R.fail("getSysUserInfoCacheById fail:" + throwable.getMessage());
            }
        };
    }
}
